Collection.js ➔ describe(ꞌCollectionꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 86

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 86
rs 8.6583

5 Functions

Rating   Name   Duplication   Size   Complexity  
B Collection.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 25 1
A Collection.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 20 1
B Collection.js ➔ ... ➔ it(ꞌBuildꞌ) 0 24 1
A Collection.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 4 1
A Collection.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('Collection', function(){
5
  
6
  it('Create plain', function(){
7
    assert.instanceOf(new GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor with new.');
8
    assert.instanceOf(GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor without new.');
9
  });
10
  
11
  it('Create with JSON', function(){
12
    var collection = GedcomX.Collection({
13
      id: 'collection',
14
      lang: 'en-US',
15
      content: [{
16
        resourceType: 'http://gedcomx.org/Record',
17
        count: 183429102,
18
        completeness: .8237
19
      }],
20
      title: 'Collection Title',
21
      size: 183429102,
22
      attribution: { 
23
        contributor: { resource: 'https://myapp.com/contributor'},
24
        created: 1111338494969,
25
        creator: { resource: 'https://myapp.com/creator'},
26
        modified: 1111338494969
27
      }
28
    });
29
    assert.equal(collection.getId(), 'collection');
30
    assert.equal(collection.getLang(), 'en-US');
31
    assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record');
32
    assert.equal(collection.getTitle(), 'Collection Title');
33
    assert.equal(collection.getSize(), 183429102);
34
    assert(GedcomX.Attribution.isInstance(collection.getAttribution()));
35
  });
36
  
37
  it('Build', function(){
38
    var collection = GedcomX.Collection()
39
      .setId('collection')
40
      .setLang('en-US')
41
      .addContent({
42
        resourceType: 'http://gedcomx.org/Record',
43
        count: 183429102,
44
        completeness: .8237
45
      })
46
      .setTitle('Collection Title')
47
      .setSize(183429102)
48
      .setAttribution({ 
49
        contributor: { resource: 'https://myapp.com/contributor'},
50
        created: 1111338494969,
51
        creator: { resource: 'https://myapp.com/creator'},
52
        modified: 1111338494969
53
      });
54
    assert.equal(collection.getId(), 'collection');
55
    assert.equal(collection.getLang(), 'en-US');
56
    assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record');
57
    assert.equal(collection.getTitle(), 'Collection Title');
58
    assert.equal(collection.getSize(), 183429102);
59
    assert(GedcomX.Attribution.isInstance(collection.getAttribution()));
60
  });
61
  
62
  it('toJSON', function(){
63
    var data = {
64
      id: 'collection',
65
      lang: 'en-US',
66
      content: [{
67
        resourceType: 'http://gedcomx.org/Record',
68
        count: 183429102,
69
        completeness: .8237
70
      }],
71
      title: 'Collection Title',
72
      size: 183429102,
73
      attribution: { 
74
        contributor: { resource: 'https://myapp.com/contributor'},
75
        created: 1111338494969,
76
        creator: { resource: 'https://myapp.com/creator'},
77
        modified: 1111338494969
78
      }
79
    }, collection = GedcomX.Collection(data);
80
    assert.deepEqual(collection.toJSON(), data);
81
  });
82
  
83
  it('constructor does not copy instances', function(){
84
    var obj1 = GedcomX.Collection();
85
    var obj2 = GedcomX.Collection(obj1);
86
    assert.strictEqual(obj1, obj2);
87
  });
88
  
89
});